Component({
  properties: {
    // 导航栏背景色（支持RGB/HEX）
    bgColor: {
      type: String,
      value: 'red'
    },
    // 标题文字颜色
    titleColor: {
      type: String,
      value: 'white'
    },
    showBack: {
      type: Boolean,
      value: true
    },
    // 自定义class
    customClass: {
      type: String,
      value: ''
    },
    title: {
      type: String,
      value: '万家顺送水'
    },
    description: {
      type: String,
      value: ''
    }
  },

  data: {
    statusBarHeight: 0,
    navHeight: 0,
    capsuleInfo: {}
  },

  lifetimes: {
    attached() {
      this.calcLayout()
    }
  },

  methods: {
    // 计算布局信息
    calcLayout() {
      const systemInfo = wx.getSystemInfoSync()
      const capsule = wx.getMenuButtonBoundingClientRect()
      const navHeight = (capsule.bottom + capsule.top - systemInfo.statusBarHeight)
      this.setData({
        statusBarHeight: systemInfo.statusBarHeight,
        navHeight,
        navHeightWithoutTime: navHeight - 16,
        capsuleInfo: {
          top: capsule.top,
          right: systemInfo.windowWidth - capsule.right
        },
        showBack: getCurrentPages().length > 1
      })
    },
    handleBackClick() {
      wx.navigateBack({
        delta: 1
      });
    },
    handleTitleClick() {
      this.triggerEvent('titleclick')
    }
  }
})